import * as constants from './constants';
import axios from 'axios';

const changeDetail = (title,content) => ({
    type: constants.CHANGE_DETAIL,
    title,
    content
})

export const getDetail = (id) => {
    return (dispatch) => {
        axios.get('/api/detail.json?id=' + id).then((res) => {
            // result 是接口里面获取到的数据
            const result = res.data.data;
            const action = changeDetail(result.title,result.content);
            dispatch(action);
        }).catch((err)=>{console.error('wrong');})
    }
};